<template>
    <div class="Test">
        <!-- <el-form
        ref="testdata"
        :model="testdata"
        :rules="rules"
        class="form">
            <el-form-item label="模型" prop="model">
                <el-select v-model="testdata.model" placeholder="请选择模型">
                    <el-option label="VGG" value="VGG"></el-option>
                    <el-option label="ResNet" value="ResNet"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="输入原始数据集路径" prop="real_path">
                {{testdata.real_path}}
                <el-input v-model="testdata.real_path"></el-input>
            </el-form-item>
            <el-form-item label="输入对抗样本路径" prop="adv_path">
                {{testdata.adv_path}}
                <el-input v-model="testdata.adv_path"></el-input>
            </el-form-item>
            <el-form-item label="输入对抗样本路径">
                {{session_store}}
                <el-select v-model="testdata.adv_path" placeholder="请选择对抗样本路径">
                    <el-option v-for="(item,index) in session_store" :key=index  :label="item.key" :value="item.value.gen_path"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitFormdata('testdata')">提交</el-button>
                <el-button type="danger"  @click="resetFormdata('testdata')">重置</el-button>
            </el-form-item>
        </el-form> -->
        <ReadForTest/>
        <ShowTestRe  />
    </div>
</template>

<script>
    import axios from 'axios'
    import ReadForTest from './div_level/ReadForTest.vue'
    import ShowTestRe from './div_level/ShowTestRe.vue'
    export default{
        name : "TestTable",
        components:{ReadForTest,ShowTestRe},
        data(){
            return {
                testdata:{
                    model:'',
                    real_path:'',
                    adv_path:''
                },
                rules:{
                    model:[
                        { required: true, message: '请选择模型', trigger: 'change' }
                    ],
                    real_path:[
                        {required:true,message:'请输入原始数据集路径，否则系统采用默认数据集'}
                    ],
                    adv_path:[
                        {required:true,message:'请输入对抗样本路径，否则系统采用默认对抗样本'}
                    ]
                },
                session_store:null
            }
        },
        mounted(){
            let allData = [];
            for( let i = 0 ;i < sessionStorage.length ;i++ ){
                let key = sessionStorage.key(i);
                let value = sessionStorage.getItem(key);
                let istrue = true;
                let path = ''
                try{
                     path = value.gen_path || '';
                    console.log(path)
                }catch(e){
                    istrue = false;
                }
                if(path.length > 0){
                    istrue = true;
                }else{
                    istrue = false;
                }
                if(istrue){
                    try{
                        allData.push({key : key,value: JSON.parse(value)})
                    }catch(e){
                        allData.push({key:key,value:value})
                    }
                }
            }
            this.session_store = allData
        },
        methods:{
            submitFormdata(Formname){
                this.$refs[Formname].validate(
                    (valid,unpass)=>{
                        if(valid){
                            axios.post('/api/testing/test',{
                                model : this.testdata.model,
                                real_path: this.testdata.real_path,
                                adv_path: this.testdata.adv_path
                            }).then(
                                res=>{
                                  this.$DailyRecord(res.data.status == 200?'操作成功':'操作失败')

                                  console.log(JSON.stringify(res));
                                    // alert(JSON.stringify(res));
                                }
                            )
                        }else{
                            let messages = Object.keys(unpass).map(key => {
                                return unpass[key][0].message;
                            }).join('<br>')
                            this.$notify({
                                title:'提示',
                                message:messages,
                                offset: 120,
                                type:'warning',
                                dangerouslyUseHTMLString: true
                            })
                        }
                    }
                )
            },
            resetFormdata(Formname){
                //返回初始状态
                this.$refs[Formname].resetFields()
            }
        }
    }
</script>
<style scoped>
/* @import url('../assets/css/wbt_form.css'); */
.Test{
    width: 100vh;
    height: auto;
    min-height: 100vh;
    margin: 0 auto;
}
</style>
